package com.zj.leetcode;

import java.util.Arrays;

public class A26删除有序数组中的重复项 {

    public static void main(String[] args) {
        int[] test={-3,-1,0,0,0,3,3};
        System.out.println(removeDuplicates(test));
    }

    public static int removeDuplicates(int[] nums) {
        int count=0;
        int obj=nums[0];
        for (int i = 1; i < nums.length; i++) {
            if(nums[i]==obj){
                count++;
                nums[i]=nums[0]-1;
            }else {
                obj=nums[i];
            }

        }
        for (int i=1 ; i < nums.length-count; i++) {
            if(nums[i]==nums[0]-1){
                int j=i;
                while(j<nums.length&&nums[j]==nums[0]-1){
                    j++;
                }
                if(j>=nums.length)break;
                nums[i]=nums[j];
                nums[j]=nums[0]-1;
            }

        }
        System.out.println(Arrays.toString(nums));
        return nums.length-count;
    }



}
